home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Business & Presentations
/
Business and Presentations - Volume 1 (1995)(Sideface)(NL).iso
/
hputils
/
djprnt
/
parms.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-10
|
3KB
|
107 lines
/*
PARMS.CPP
Copyright (c) Les Hancock 1990
*/
#include <stdio.h>
#include <stdlib.h>
#include <stream.hpp>
#include "list.hpp"
#include "parms.hpp"
static void help(void);
/*
Constructor sets defaults, parses the command line for options
and for file names. NB: values are not currently being validated.
*/
parms::parms(int argc, char *argv[])
{
filebuf *flag = 0; // set to 1 when valid output file is opened
pq = 0; // print quality defaults to lowest value
title = 1; // default: titles at head of page
tab_size = 3;
max_rows = 48;
max_cols = 196; // suitable for 20 chars per inch
gutter = 6;
cpi = 20; // 20 chars per horizontal inch
lpi = 6; // 6 lines per vertical inch
if (argc == 1) // if no arguments on command line, user needs help
help();
for (int i = 1; i < argc; ++i) // for all command-line args
if (*argv[i] == '-') // options begin with -
{
char *ptr = argv[i] + 1;
switch(*ptr)
{
case '?': // user wants help
help(); // ends program
case 'h': // horizontal spacing: 10, 16, 20 cpi
if ((cpi = atoi(++ptr)) <= 10)
{
cpi = 10;
max_cols = 100;
gutter = 4;
}
else if (cpi <= 17)
{
cpi = 16;
max_cols = 164;
gutter = 6;
}
break;
case 'n': // suppress page headers
title = 0;
break;
case 'q': // print quality -- should be 0, 1 or 2
pq = *++ptr - '0';
break;
case 't': // tab expansion (max 31 spaces)
tab_size = atoi(++ptr);
break;
case 'o': // output file name follows
if (flag != 0) // if somebody's already opened a file
fp_out.close(); // close it, use only last file named
if ((flag = fp_out.open(++ptr, output)) == 0)
{
cerr << "can't open '" << ptr << "' for output";
exit(1);
}
break;
case 'v': // vertical spacing: 6 or 8 lines per inch
if ((lpi = atoi(++ptr)) > 6)
{
lpi = 8;
max_rows = 63; // not 64, for some reason
}
break;
default:
cerr << "unknown option " << argv[i] << '\n';
}
}
else if (*argv[i] == '?')
help();
else // it was a file name, not an option -- add it to the list
file_list.push_file_name(argv[i]);
if (flag == 0) // no output file was specified
fp_out.open("LPT1", output);
}
static void
help()
{
cout <<
"\nusage: djprint [-n] [-tx] [-qx] [-vx] "
"[-hxx] [[-]?] [-ofnam] file [file...]\n\n"
"\t-n: no page headers (headers by default)\n"
"\t-tx: expand tabs to x spaces (default 3)\n"
"\t-qx: printer quality 0, 1 or 2; 0 = lowest (default 0)\n"
"\t-vx: x = 6 or 8 lines per inch (default 6)\n"
"\t-hxx: xx = 10, 16 or 20 characters per inch (default 20)\n"
"\t? or -?: show this help message\n"
"\t-ofnam: output to file 'fnam' (default: LPT1)\n\n"
"Version 1.0 copyright (c) Les Hancock 1990 (CIS 74156,3262; "
"Prodigy RRMT53A)\n";
exit(-1);
}